/**
 * auth-sso-filter
 * @authors 杨兴洲（of2502）
 * @date    2017/5/22 0022 14:07
 * @version 1.0
 */
import getUserInfo from "../util/sso-util";
import logger from "../util/logger";
import CONFIG from "../config";
export default (req, res, next) => {
    (async () => {
        try {
            logger.info('请求方法',req.path);
            let {userId: userID} = await getUserInfo(req);
            res.locals.userID = userID;
            logger.info("用户编号", userID);
            const whiteUserList = CONFIG.WHITE_USER_LIST || [];
            const isBetaVersion = whiteUserList && whiteUserList.length > 0;
            const isInList = whiteUserList.indexOf(userID) >= 0;
            if (isBetaVersion && !isInList) {
                logger.info("用户不在内测名单中");
                return res.status(200).json({errcode: 90001, errmsg: "用户不在内测名单中"});
            }
            next();
        } catch (err) {
            res.status(200).json({errcode: 99999, errmsg: "SSO验证失败"});
        }
    })();
}
